package com.efast.dmom.mgmt.service.wms.impl;
import java.util.Date;
import java.util.List;

import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.mgmt.dao.wms.TwBasPartRuleDao;
import com.efast.dmom.mgmt.dao.wms.TwBasPartRuleHeaderDao;
import com.efast.dmom.mgmt.entity.wms.TwBasPartRule;
import com.efast.dmom.mgmt.entity.wms.TwBasPartRuleHeader;
import com.efast.dmom.mgmt.service.wms.TwBasPartRuleHeaderService;
import com.efast.dmom.mgmt.utils.Assist;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class TwBasPartRuleHeaderServiceImpl implements TwBasPartRuleHeaderService{
    @Autowired
    private TwBasPartRuleHeaderDao twBasPartRuleHeaderDao;
    @Autowired
    private TwBasPartRuleDao twBasPartRuleDao;
    
    @Override
    public long getTwBasPartRuleHeaderRowCount(Assist assist){
        return twBasPartRuleHeaderDao.getTwBasPartRuleHeaderRowCount(assist);
    }
    @Override
    public List<TwBasPartRuleHeader> selectTwBasPartRuleHeader(Assist assist){
        return twBasPartRuleHeaderDao.selectTwBasPartRuleHeader(assist);
    }
    @Override
    public TwBasPartRuleHeader selectTwBasPartRuleHeaderByObj(TwBasPartRuleHeader obj){
        return twBasPartRuleHeaderDao.selectTwBasPartRuleHeaderByObj(obj);
    }
    @Override
    public TwBasPartRuleHeader selectTwBasPartRuleHeaderById(Integer id){
        return twBasPartRuleHeaderDao.selectTwBasPartRuleHeaderById(id);
    }
    @Override
    public int insertTwBasPartRuleHeader(TwBasPartRuleHeader value){
        return twBasPartRuleHeaderDao.insertTwBasPartRuleHeader(value);
    }
    @Override
    public int insertNonEmptyTwBasPartRuleHeader(TwBasPartRuleHeader value){
        return twBasPartRuleHeaderDao.insertNonEmptyTwBasPartRuleHeader(value);
    }
    @Override
    public int insertTwBasPartRuleHeaderByBatch(List<TwBasPartRuleHeader> value){
        return twBasPartRuleHeaderDao.insertTwBasPartRuleHeaderByBatch(value);
    }
    @Override
    public int deleteTwBasPartRuleHeaderById(Integer id){
        return twBasPartRuleHeaderDao.deleteTwBasPartRuleHeaderById(id);
    }
    @Override
    public int deleteTwBasPartRuleHeader(Assist assist){
        return twBasPartRuleHeaderDao.deleteTwBasPartRuleHeader(assist);
    }
    @Override
    public int updateTwBasPartRuleHeaderById(TwBasPartRuleHeader enti){
        return twBasPartRuleHeaderDao.updateTwBasPartRuleHeaderById(enti);
    }
    @Override
    public int updateTwBasPartRuleHeader(TwBasPartRuleHeader value, Assist assist){
        return twBasPartRuleHeaderDao.updateTwBasPartRuleHeader(value,assist);
    }
    @Override
    public int updateNonEmptyTwBasPartRuleHeaderById(TwBasPartRuleHeader enti){
        return twBasPartRuleHeaderDao.updateNonEmptyTwBasPartRuleHeaderById(enti);
    }
    @Override
    public int updateNonEmptyTwBasPartRuleHeader(TwBasPartRuleHeader value, Assist assist){
        return twBasPartRuleHeaderDao.updateNonEmptyTwBasPartRuleHeader(value,assist);
    }
    
    @Override
    public String insertPartRule(TwBasPartRuleHeader twBasPartRuleHeader) {
    		String msg = "";
    		//插入零件规则头信息,同一零件不可以选择相同的规则组
    		Assist assist = new Assist();
    		assist.setRequires(Assist.andEq("part_no_version",twBasPartRuleHeader.getPartNoVersion()));
    		assist.setRequires(Assist.andEq("rule_type", twBasPartRuleHeader.getRuleType()));
    		assist.setRequires(Assist.andEq("suppl_no", twBasPartRuleHeader.getSupplNo()));
    		List<TwBasPartRuleHeader> headerList = this.selectTwBasPartRuleHeader(assist);
    		if(headerList!=null&&headerList.size()>0) {
    			msg = "201";//数据存在重复
    		}else {
    			twBasPartRuleHeader.setCreateTime(new Date());
    			twBasPartRuleHeader.setCreateUser(SpringWebUtils.getRequestUser());
    			twBasPartRuleHeader.setCompanyCode(SpringWebUtils.getRequestCompany());
    			twBasPartRuleHeaderDao.insertPartRuleHeader(twBasPartRuleHeader);
    			//插入零件规则信息
    			List<TwBasPartRule> partRuleList = twBasPartRuleDao.selectPartRule(twBasPartRuleHeader.getRuleGroupId(),twBasPartRuleHeader.getTwBasPartRuleHeaderId());
    			twBasPartRuleDao.insertTwBasPartRuleByBatch(partRuleList);
    		}
    		return msg;
    }

    public TwBasPartRuleHeaderDao getTwBasPartRuleHeaderDao() {
        return this.twBasPartRuleHeaderDao;
    }

    public void setTwBasPartRuleHeaderDao(TwBasPartRuleHeaderDao twBasPartRuleHeaderDao) {
        this.twBasPartRuleHeaderDao = twBasPartRuleHeaderDao;
    }

}